package com.xxxy.dongyexuan.mapper;

import com.xxxy.dongyexuan.po.Order;
import com.xxxy.dongyexuan.po.Technology;
import org.apache.ibatis.annotations.*;
import org.mybatis.spring.annotation.MapperScan;

import java.util.List;

@MapperScan("com.xxxy.dongyexuan.demobeautyhaird.mapper")
public interface IOrderMapper {

    @Select("SELECT * FROM `order` WHERE pay_status = 0 and trans_type in(0, 1) ")
    public List<Order> findUnKnownOrderAll();

    @Delete("DELETE FROM `order` WHERE order_id = #{orderId}")
    public int deleteById(@Param("orderId") String orderId);

    @Select("SELECT * FROM `order` WHERE order_id = #{orderId}")
    public Order selectById(@Param("orderId") String orderId);

    @Insert("INSERT INTO `order` (order_id, payment_type, trans_type, total_amt, real_amt, uid, rid, pay_status, pay_success_time, create_time, update_time) VALUES (#{orderId}, #{paymentType}, #{transType}, #{totalAmt}, #{realAmt}, #{uid}, #{rid}, #{payStatus}, #{paySuccessTime}, #{createTime}, #{updateTime})")
    public int save(Order order);

    @Update("UPDATE `order` set pay_status = #{payStatus}, pay_success_time = #{paySuccessTime}, update_time = #{updateTime} WHERE order_id = #{orderId}")
    public int updateSuccessOrder(Order order);

    @Update("UPDATE `order` set pay_status = #{payStatus}, update_time = #{updateTime}, pay_msg = #{payMsg} WHERE order_id = #{orderId}")
    public int updateFailureOrder(Order order);

    @Select("select count(*) from `order` where uid = #{uid} and pay_status = 1")
    public int getcount(@Param("uid") int uid);

    @Update("UPDATE `order` set query_count = query_count + 1 WHERE order_id = #{orderId}")
    public int updateQueryCount(@Param("orderId") String orderId);

    @Select("SELECT * FROM `order` WHERE uid = #{uid} and pay_status = 1 order by pay_success_time desc LIMIT #{from}, #{pagesize}")
    public List<Order> findByOrderPage(@Param("uid") int uid, @Param("from") int from, @Param("pagesize") int pagesize);

}
